package no.ffi.gismoidm.servicestubs;

import java.util.Iterator;
import java.util.Properties;
import no.ffi.gismoidm.utils.IdentityStatement;

/**
 * This object contains properties and attributes regarding the
 * calling client. The object offers get methods for obtaining
 * these properties
 * 
 * @author anders
 */
public class SubjectProperties {
    IdentityStatement clientIS;
    
    public SubjectProperties(IdentityStatement is) {
        clientIS = is;
    }
    
    public IdentityStatement getIdentityStatement() { return clientIS; }
    public Properties getAttributes() { return getAttributeAsProperties(clientIS); }
    
    private Properties getAttributeAsProperties(IdentityStatement identityStatement) {
        Iterator it = identityStatement.getSubjectAttributes().iterator();
        Properties prop = new Properties();
        try {
            while (it.hasNext()) {
                String name = (String)it.next();
                String value = (String)it.next();
                prop.setProperty(name, value);
            }
            // Throw in the subject's DN too
            prop.setProperty("SubjectName",identityStatement.getSubjectName());
        } catch (Exception e) {e.printStackTrace();}
        return prop;
    }

}
